13. Fourier Transform In Practice

Heading

Fourier Transform In Practice

ND320 C4 L1 13 Fourier Transform In Practice

Fourier Transform in Practice Summary

We learned how to apply the theory and understanding of what a fourier transform is to actually solve some problems.

Let's make a signal that is composed of two sine waves at 2 Hz and 3 Hz plus some random noise. We will be using the np.fftmodule to compute the Fourier transform with the two main functions below:

  • rfft - computes the actual Fourier transform coefficients
  • rfftfreq - tells us the frequencies for which we are computing the Fourier transform

We then examined freqs to see that the FFT samples the Fourier transform uniformly from 0 Hz to the Nyquist frequency, which in this case is 25 Hz because our sampling rate is 50 Hz.
We also saw the Fourier transform coefficients and only examined the magnitudes.
Plotting the FFT, we see that the signal is composed primarily of two frequencies (2 and 3Hz) and a little bit of everything else (from the random noise).

We also saw how zero-padding could be used to visualize sinusoids with frequencies that are not present in freqs. To visualize at frequencies not in freqs, we need to sample twice as often and we can do this by adding 0s to the end of the signal. However, we also see this rippling, which is an artifact of padding the signal with 0s, which is the trade-off when doing zero-padding.

ND320 C4 L1 14 Inverse FFT

Fourier Transform recap

We just learned about inverse Fourier Transform in which we used the np.fft module to compute the inverse Fourier transform with the function irfft.

We started with a noisy signal and removed all the frequency components not in the range, in this case, 2Hz and 3Hz. And we saw a recovered signal that looked very close to the signal we saw in the previous video.

But we did the process again from 2.15Hz and 2.95Hz. The recovered signal looked a bit distorted and not what we'd expect. This is because zeroing out Fourier coefficients is not the best way to filter a signal.

We then used scipy to bandpass filter our signal for us. A bandpass filter will remove all frequency components outside of a given passband. Let's bandpass filter our signal with a passband from 1 Hz to 4 Hz. This way, our desired frequencies of 2.15 Hz and 2.95 Hz are well within the passband. And now, our recovered signal looks very similar to what we want.

In this course, we will always bandpass our signals before processing them.

Notebook Review

If you wanted to interact with the notebook in the video, you can access it here in the repo /intro-to-dsp/walkthroughs/fourier-transform-II/ or in the workspace below.

Code

If you need a code on the https://github.com/udacity.